package com.penghk.hangzhouhouseprice.service;

import com.alibaba.fastjson.JSON;
import com.penghk.hangzhouhouseprice.entity.AreaPrice;
import com.penghk.hangzhouhouseprice.handler.GanJiNewHousePriceHandler;
import com.penghk.hangzhouhouseprice.handler.MailSendHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GanjiNewHousePriceService {

    @Value("${mail.toUser}")
    private String toUser;

    @Autowired
    GanJiNewHousePriceHandler ganJiHousePriceHandler;

    @Autowired
    MailSendHandler mailSendHandler;

    public String getHousePrice() {
        List<AreaPrice> areaPriceList = getPriceList();
        String msg =  JSON.toJSONString(areaPriceList);

        StringBuffer buf = new StringBuffer();
        for (AreaPrice areaPrice : areaPriceList) {
            buf.append(areaPrice.toString());
        }
        buf.append("数据来源 ： 赶集网\n");
        mailSendHandler.sendMsg(buf.toString() , toUser);
        return msg;
    }

    private List<AreaPrice> getPriceList() {
        AreaPrice areaPrice1 = ganJiHousePriceHandler.getXiHuPrice();
        AreaPrice areaPrice2 = ganJiHousePriceHandler.getGongShuPrice();
        AreaPrice areaPrice3 = ganJiHousePriceHandler.getShangchengPrice();
        AreaPrice areaPrice4 = ganJiHousePriceHandler.getXiachengPrice();
        AreaPrice areaPrice5 = ganJiHousePriceHandler.getJiangganPrice();
        AreaPrice areaPrice6 = ganJiHousePriceHandler.getBinjiangPrice();
        AreaPrice areaPrice7 = ganJiHousePriceHandler.getXiaoshanPrice();
        AreaPrice areaPrice8 = ganJiHousePriceHandler.getYuhangPrice();
        AreaPrice areaPrice9 = ganJiHousePriceHandler.getLinanPrice();
        AreaPrice areaPrice10 = ganJiHousePriceHandler.getFuyangPrice();
        AreaPrice areaPrice11 = ganJiHousePriceHandler.getTongluPrice();
        AreaPrice areaPrice12 = ganJiHousePriceHandler.getJiandePrice();
        AreaPrice areaPrice13 = ganJiHousePriceHandler.getChunanPrice();
        AreaPrice areaPrice14 = ganJiHousePriceHandler.getHangzhouzhoubianPrice();
        List<AreaPrice> areaPriceList = new ArrayList<>();
        areaPriceList.add(areaPrice1);
        areaPriceList.add(areaPrice2);
        areaPriceList.add(areaPrice3);
        areaPriceList.add(areaPrice4);
        areaPriceList.add(areaPrice5);
        areaPriceList.add(areaPrice6);
        areaPriceList.add(areaPrice7);
        areaPriceList.add(areaPrice8);
        areaPriceList.add(areaPrice9);
        areaPriceList.add(areaPrice10);
        areaPriceList.add(areaPrice11);
        areaPriceList.add(areaPrice12);
        areaPriceList.add(areaPrice13);
        areaPriceList.add(areaPrice14);
        return areaPriceList;
    }
}
